﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using DevExpress.Web.ASPxClasses;	
using System.Data;



public partial class pSubCategorias : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["Email"] != null)
            Master.UsuarioRegistrado(Session["Email"].ToString());
            lblIdCategoria.Text = Request["IDCategoria"];
            CargarSubCategorias(long.Parse(Request["IDCategoria"].ToString()));
        }

        if (gvGrilla.IsCallback)
        {
            CargarSubCategorias(long.Parse(Request["IDCategoria"].ToString()));
        }

    }

    private void CargarSubCategorias(long idCategoria)
    {
        List<SubCategoria> ListaSubCategorias = SubCategoria.ObtenerVariosPorCategotia(idCategoria);
        gvGrilla.DataSource = ListaSubCategorias;
        gvGrilla.DataBind();
    }


    protected void btnNuevoUsuario_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("pSubCategoriaModificarDatos.aspx?IDCategoria=" + lblIdCategoria.Text);
    }


    protected void gvGrilla_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
    {
        SubCategoria oSubCategoria = (Entities.SubCategoria)(gvGrilla.GetRow(e.VisibleIndex));
        if (e.ButtonID == "Modificar")
            ASPxWebControl.RedirectOnCallback(String.Format("pSubCategoriaModificarDatos.aspx?IDSubCategoria={0}&IDCategoria={1}", oSubCategoria.IDSubCategoria, lblIdCategoria.Text));
        if (e.ButtonID == "Eliminar")
            ASPxWebControl.RedirectOnCallback(String.Format("pSubCategoriaEliminar.aspx?IDSubCategoria={0}&IDCategoria={1}", oSubCategoria.IDSubCategoria, lblIdCategoria.Text));
    }

    protected void btnSiguiente_Click(object sender, EventArgs e)
    {
        Response.Redirect("pCategorias.aspx");
    }
}